using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;

namespace SampleNs
{
    /// <summary>
    /// Sample Service
    /// </summary>
    [WebService(Namespace = "http://sampleService/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService()]
    public class SampleService : System.Web.Services.WebService
    {
        public SampleService()
        {

            //Uncomment the following line if using designed components 
            //InitializeComponent(); 
        }

        /// <summary>
        /// Sample method not doing much really
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public Sample GetSample()
        {
            Sample sample = new Sample("This is a sample name " + DateTime.UtcNow.ToLongTimeString());
            sample.Id = 1;
            sample.Description = "This is a sample description";
            sample.OtherSamples = new List<Sample>();
            for(int i = 0; i< 10; i++)            sample.OtherSamples.Add(new Sample("Sample " + i.ToString()));
            return sample;
        }

        /// <summary>
        /// Gets a <see cref="Sample"/> by its Id.  Actually the <see cref="Sample.Id"/>
        /// is set to <paramref name="id"/>
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [WebMethod]
        public Sample GetSampleById(int id)
        {
            Sample sample = this.GetSample();
            sample.Id = id;
            return sample;
        }

        [Serializable]
        public class Sample : SampleBase
        {
            /// <summary>
            /// Required for Serialization
            /// </summary>
            public Sample()
            {
            }

            /// <summary>
            /// Easier construction
            /// </summary>
            /// <param name="name"></param>
            public Sample(string name)
            {
                this._name = name;
            }
            private int _id;

            public int Id
            {
                get { return _id; }
                set { _id = value; }
            }

            private string _name;

            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }

            private string _decription;

            public string Description
            {
                get { return _decription; }
                set { _decription = value; }
            }


            private List<Sample> _otherSamples;

            public List<Sample> OtherSamples
            {
                get { return _otherSamples; }
                set { _otherSamples = value; }
            }


        }
        [Serializable]
        public class SampleBase
        {
            private string _baseName;

            public string BaseName
            {
                get { return this._baseName; }
                set { this._baseName = value; }
            }

        }
    }
}

